#include "process.h"
#define NUM 101
#define TYPE '='

void process_v1()
{
    char buffer[NUM];
    memset(buffer,0,sizeof(buffer));
    const char* lable = "|/-\\";
    int len = strlen(lable);
    int cnt = 0;
    while(cnt <= 100)
    {
        printf("[%-100s][%d/%][%c]\r",buffer,cnt,lable[cnt%len]);
        fflush(stdout);
        if(cnt != 100)
        {
            buffer[cnt] = TYPE;
        }
        ++cnt;
        usleep(50000);
    }
    printf("\n");
}

void process_v2(double total,double current)
{ 
    char buffer[NUM];
    memset(buffer,0,sizeof(buffer));
    const char* lable = "|/-\\";
    int len = strlen(lable);
    static int cnt = 0;
    int num = (int)current*100/total;
    double rate = current*100/total;
    int i = 0;
    for(i = 0;i < num;++i)
    {
        buffer[i] = TYPE;
    }
    printf("[%-100s][%.2lf%%][%c]\r",buffer,rate,lable[cnt%len]);
    fflush(stdout);
    ++cnt;
}

